import request from "@/utils/request";

export function login(data) {
  return request({
    url: "/user/login",
    method: "post",
    data,
  });
}

export function getInfo(token) {
  return request({
    url: "/user/info",
    method: "get",
    params: { token },
  });
}

export function logout(token) {
  return request({
    url: "/user/logout",
    method: "post",
    params: { token },
  });
}

export function regesiter(data) {
  if (data.subject && data.subject.length > 0) {
    data.subject = JSON.stringify(data.subject);
  } else {
    data.subject = null;
  }
  return request({
    url: "/user/regesiter",
    method: "post",
    data,
  });
}

export function setPassword(data) {
  return request({
    url: "/user/setPassword",
    method: "post",
    data,
  });
}

export function updateName(name) {
  return request({
    url: `/user/updateName/${name}`,
    method: "put",
  });
}

export function uploadAvatar(avatarData) {
  return request({
    url: "/user/uploadAvatar",
    method: "post",
    data: { avatar: avatarData },
  });
}
